package com.gitee.wsl.collections.iterator

import com.gitee.wsl.func.procedure.Procedure


class TapIterator<T>(
    private val iterator: Iterator<T>,
    private val procedure: Procedure<in T>
) : Iterator<T> {
    constructor(iterable: Iterable<T>, procedure: Procedure<in T>) : this(iterable.iterator(), procedure)

    override fun hasNext(): Boolean {
        return this.iterator.hasNext()
    }

    override fun next(): T {
        val next = this.iterator.next()
        this.procedure.value(next)
        return next
    }
}
